package com.skyline.wo.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.base.type.Activity;
import com.skyline.wo.model.Album;

/**
 * Album RowMapper
 * 
 * @see RowMapper
 * @author wuqh
 * @version 1.00
 */
public class AlbumMapper implements RowMapper<Album> {
	private static final AlbumMapper MAPPER = new AlbumMapper();

	public static final String COLUMN_ID = "id";
	public static final String COLUMN_OWNER_ID = "ownerId";
	public static final String COLUMN_OWNER_NICKNAME = "ownerNickname";
	public static final String COLUMN_OWNER_PORTRAIT = "ownerPortrait";
	public static final String COLUMN_ALBUM_NAME = "albumName";
	public static final String COLUMN_PLACE = "place";
	public static final String COLUMN_DESCRIPTION = "description";
	public static final String COLUMN_COVER = "cover";
	public static final String COLUMN_COVER_EXT = "coverExt";
	public static final String COLUMN_PHOTO_NUM = "photoNum";
	public static final String COLUMN_COMMENT_NUM = "commentNum";
	public static final String COLUMN_VISIT_NUM = "visitNum";
	public static final String COLUMN_UP = "up";
	public static final String COLUMN_DOWN = "down";
	public static final String COLUMN_SHARE_NUM = "shareNum";
	public static final String COLUMN_CREATE_TIME = "createTime";
	public static final String COLUMN_UPATE_TIME = "updateTime";
	public static final String COLUMN_AUTHORITY = "authority";
	public static final String COLUMN_ACTIVITY = "activity";

	public static AlbumMapper getMapper() {
		return MAPPER;
	}

	@Override
	public Album mapRow(ResultSet rs, int rowNum) throws SQLException {
		Album album = new Album();
		album.setId(rs.getLong(COLUMN_ID));
		album.setOwnerId(rs.getLong(COLUMN_OWNER_ID));
		album.setOwnerNickname(rs.getString(COLUMN_OWNER_NICKNAME));
		album.setOwnerPortrait(rs.getString(COLUMN_OWNER_PORTRAIT));
		album.setAlbumName(rs.getString(COLUMN_ALBUM_NAME));
		try {
			album.setPlace(rs.getString(COLUMN_PLACE));
		} catch (SQLException e) {
			album.setPlace(null);
		}
		try {
			album.setDescription(rs.getString(COLUMN_DESCRIPTION));
		} catch (SQLException e) {
			album.setDescription(null);
		}
		album.setPhotoNum(rs.getInt(COLUMN_PHOTO_NUM));
		album.setCommentNum(rs.getInt(COLUMN_COMMENT_NUM));
		album.setVisitNum(rs.getInt(COLUMN_VISIT_NUM));
		album.setUp(rs.getInt(COLUMN_UP));
		album.setDown(rs.getInt(COLUMN_DOWN));
		album.setShareNum(rs.getInt(COLUMN_SHARE_NUM));
		album.setCover(rs.getString(COLUMN_COVER));
		album.setCoverExt(rs.getString(COLUMN_COVER_EXT));
		album.setCreateTime(rs.getTimestamp(COLUMN_CREATE_TIME));
		album.setUpdateTime(rs.getTimestamp(COLUMN_UPATE_TIME));
		album.setAuthority(rs.getInt(COLUMN_AUTHORITY));
		album.setActivity(Activity.valueOf(rs.getString(COLUMN_ACTIVITY)));
		return album;
	}

}
